﻿Imports System.Security.Permissions
Imports Microsoft.Win32
Imports System.Text


Public Class ClsEncoding


    Public Property EncoderCodePage()

        Get

            Dim ReturnKey As RegistryKey = Registry.LocalMachine.OpenSubKey( _
                                           "Software\Rm Technologies\Framework\" & ProductString)

            EncoderCodePage = ReturnKey.GetValue("EncCodePage")

            ReturnKey = Nothing

        End Get

        Set(ByVal value)

            Dim WriteKey As RegistryKey = Registry.LocalMachine.CreateSubKey( _
                                          "Software\Rm Technologies\Framework\" & ProductString)

            WriteKey.SetValue("EncCodePage", value)
            WriteKey = Nothing

        End Set

    End Property


    ''' <summary>
    ''' Get the encoding display name from the provided code page.
    ''' </summary>
    ''' <param name="codePage">The encoding code page.</param>
    ''' <returns>The encoding display name.</returns>
    ''' <remarks></remarks>
    Public Function GetEncodingDisplayName(Optional ByVal codePage As Integer = 0) As String

        Dim EncInfo As EncodingInfo
        Dim Enc As Encoding = Encoding.GetEncoding(0)
        Dim returnString As String = "Unknown"

        For Each EncInfo In Encoding.GetEncodings()

            If EncInfo.CodePage = codePage Then
                returnString = EncInfo.DisplayName
            ElseIf codePage = 0 Then
                returnString = "Default - " & Enc.EncodingName
            End If

        Next EncInfo

        Return returnString

    End Function


End Class